﻿using OxyPlot;
using OxyPlot.Series;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace JVMTI_CORE_SHELL.Converters
{
    class LifeCycleToPlotModel : IValueConverter
    {
        //Let us reflect directly.
        static OxyColor Accent;
        static LifeCycleToPlotModel()
        {
            Accent = OxyColor.FromArgb(App.AccentBrush.Color.A, App.AccentBrush.Color.R, App.AccentBrush.Color.G, App.AccentBrush.Color.B);
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var contentionBreakDown = value as IEnumerable<KeyValuePair<string, double>>;
            var plotModel1 = new PlotModel();
            plotModel1.Title = "Resource Contention Breakdown";
            var pieSeries1 = new PieSeries();
            pieSeries1.InsideLabelColor = OxyColors.White;
            pieSeries1.InsideLabelPosition = 0.8;
            pieSeries1.StrokeThickness = 2;
            pieSeries1.Slices = contentionBreakDown.Select<KeyValuePair<string, double>, PieSlice>(o => new PieSlice(o.Key, o.Value)).ToList();// new PieSlice[] { new PieSlice("Lock 1", 0.5) { Fill = Accent }, new PieSlice("Lock 2", 0.5) { Fill = Accent }, new PieSlice("Lock 2", 0.3) { Fill = Accent } };
            plotModel1.Series.Add(pieSeries1);
            plotModel1.TitleFont = "Segoe UI Light";
            return plotModel1;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    class LifeCycleToPlotVisibilityModel : IValueConverter
    {
        //Let us reflect directly.
        static OxyColor Accent;
        static LifeCycleToPlotVisibilityModel()
        {
            Accent = OxyColor.FromArgb(App.AccentBrush.Color.A, App.AccentBrush.Color.R, App.AccentBrush.Color.G, App.AccentBrush.Color.B);
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var contentionBreakDown = value as IEnumerable<KeyValuePair<string, double>>;
            return contentionBreakDown == null || contentionBreakDown.Count() == 0 ? Visibility.Collapsed : Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    class LengthToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return (int)value == 0 ? Visibility.Collapsed : Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
